//
//  CDRequestVerifyCode.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/5/18.
//

import Combine

struct CDValidateCodeStep: LoginStep {
    struct InputData {
        let userName: String
        let code: String
        let type: ValidateCodeType
    }

    func execute(_ input: InputData) -> AnyPublisher<Bool, Error> {
        Future<Bool, Error> { promise in
            let api = AuthAPI.ValidateCode(body: .init(userName: input.userName, code: input.code, type: input.type))
            NetworkManager.shared.send(api, completion: { result in
                switch result {
                    case .success(let response):
                    promise(.success(response.data ?? false))
                    case .failure(let error):
                        promise(.failure(error))
                    }
            })
        }.eraseToAnyPublisher()
    }
}
